import { ApiProperty } from '@midwayjs/swagger';
import { Rule, RuleType } from '@midwayjs/validate';
import { Column, Entity, PrimaryColumn } from 'typeorm';

export enum LeaveType {
  sick = 'sick',
  issue = 'issue',
  annual = 'annual',
}
export enum LeaveBillState {
  toSubmit = 'toSubmit',
  toAudit = 'toAudit',
  Auditted = 'auditted',
}
@Entity({
  name: 'LeaveBill',
  synchronize: false,
})
export class LeaveBill {
  @ApiProperty({ example: 'QJ20230202004' })
  @Rule(RuleType.string().allow(null).required())
  @PrimaryColumn({ type: 'varchar', length: 32 })
  leaveBillCode: string;
  @ApiProperty({ example: LeaveType.sick })
  @Rule(
    RuleType.string()
      .valid(...Object.values(LeaveType))
      .required()
  )
  @Column({
    type: 'enum',
    enum: LeaveType,
    default: LeaveType.sick,
  })
  leaveType: LeaveType;
  @ApiProperty({ example: new Date() })
  @Rule(RuleType.date().allow(null).required())
  @Column({ nullable: true })
  timeStart: Date;
  @ApiProperty({ example: new Date() })
  @Rule(RuleType.date().allow(null).required())
  @Column({ nullable: true })
  timeEnd: Date;
  @ApiProperty({ example: 'sicking...' })
  @Rule(RuleType.string().allow('').allow(null).required())
  @Column({ nullable: true })
  reason: string;
  //   身份信息
  @ApiProperty({ example: null })
  @Rule(RuleType.string().allow(null).required())
  @Column()
  applier: string;
  @ApiProperty({ example: new Date() })
  @Rule(RuleType.date().allow(null).required())
  @Column({ nullable: true })
  applyTime: Date;
  @ApiProperty({ example: null })
  @Rule(RuleType.string().allow(null).required())
  @Column({ nullable: true })
  auditor: string;
  @ApiProperty({ example: null })
  @Rule(RuleType.string().allow(null).required())
  @Column({ nullable: true })
  auditWord: string;
  @ApiProperty({ example: null })
  @Rule(RuleType.date().allow(null).required())
  @Column({ nullable: true })
  auditTime: Date;
  @ApiProperty({ example: 0 })
  @Rule(RuleType.number().required())
  @Column({ default: 0 })
  resentTimes: number;
  //   核心业务字段
  @ApiProperty({ example: LeaveBillState.toSubmit })
  @Rule(
    RuleType.string()
      .valid(...Object.values(LeaveBillState))
      .required()
  )
  @Column({
    type: 'enum',
    enum: LeaveBillState,
    default: LeaveBillState.toSubmit,
  })
  billState: LeaveBillState;
  //   modifyTime 字段用来排序 每次 修改操作都会造成字段刷新
  @ApiProperty({ example: new Date() })
  @Rule(RuleType.date().allow(null).required())
  @Column()
  modifyTime: Date;
}

export class LeaveBillInsertDto {
  @ApiProperty({ example: LeaveType.sick })
  @Rule(
    RuleType.string()
      .valid(...Object.values(LeaveType))
      .required()
  )
  leaveType: LeaveType;
  @ApiProperty({ example: new Date() })
  @Rule(RuleType.date().allow(null).required())
  @Column({ nullable: true })
  timeStart: Date;
  @ApiProperty({ example: new Date() })
  @Rule(RuleType.date().allow(null).required())
  timeEnd: Date;
  @ApiProperty({ example: 'sicking...' })
  @Rule(RuleType.string().allow('').allow(null).required())
  reason: string;
}
export class LeaveApplyQueryCondition {
  @ApiProperty({ example: Object.values(LeaveType) })
  @Rule(
    RuleType.array()
      .min(0)
      .items(RuleType.string().valid(...Object.values(LeaveType)))
  )
  //   []  ['sick'] ['sick','issue']
  leaveTypes: Array<LeaveType>;
  @ApiProperty({ example: Object.values(LeaveBillState) })
  @Rule(
    RuleType.array()
      .min(0)
      .items(RuleType.string().valid(...Object.values(LeaveBillState)))
  )
  leaveBillStates: Array<LeaveBillState>;
  @ApiProperty({ example: 1 })
  @Rule(RuleType.number().min(1).required())
  pageNum: number;
  @ApiProperty({ example: 3 })
  @Rule(RuleType.number().min(1).required())
  pageSize: number;
}
export class LeaveAuditQueryCondition {
  @ApiProperty({ example: '' })
  @Rule(RuleType.string().allow('').allow(null).required())
  applier: string;
  @ApiProperty({ example: Object.values(LeaveType) })
  @Rule(
    RuleType.array()
      .min(0)
      .items(RuleType.string().valid(...Object.values(LeaveType)))
  )
  leaveTypes: Array<LeaveType>;

  @ApiProperty({ example: 1 })
  @Rule(RuleType.number().min(1).required())
  pageNum: number;
  @ApiProperty({ example: 3 })
  @Rule(RuleType.number().min(1).required())
  pageSize: number;
}
export class LeaveBillAuditDto {
  @ApiProperty({ example: 'take care' })
  @Rule(RuleType.string().allow('').allow(null).required())
  auditWord: string;
}
